package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.model.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface EmployeeMapper extends BaseMapper<Employee> {
    @Select("SELECT COUNT(*) FROM employee")
    int countEmployees();

    @Insert("INSERT INTO employee(id, name, gender, birth_date, email, phone, address, hire_date, department_id, position, status, create_time, update_time) " +
            "VALUES(#{employee.id},#{employee.name},#{employee.gender},#{employee.birthDate},#{employee.email},#{employee.phone},#{employee.address},#{employee.hireDate},#{employee.departmentId},#{employee.position},#{employee.status},#{employee.createTime},#{employee.updateTime})")
    void insertEmployee(@Param("employee")Employee employee);

    @Select("SELECT * FROM employee WHERE id = #{id}")
    Employee selectById(int id);

    @Select("SELECT * FROM employee")
    List<Employee> getBusinessEmployees();

    @Update("UPDATE employee SET name = #{employee.name}, gender = #{employee.gender}, birth_date = #{employee.birthDate}, email = #{employee.email}, phone = #{employee.phone}, address = #{employee.address}, hire_date = #{employee.hireDate}, department_id = #{employee.departmentId}, position = #{employee.position}, status = #{employee.status}  WHERE id = #{employee.id}")
    int updateById(@Param("employee") Employee employee);
}
